package drds.server.sqlparser.sqlobject.statement.query.union_query;

import drds.server.sqlparser.sqlobject.AbstractSqlObject;
import drds.server.sqlparser.sqlobject.statement.query.IQuery;
import drds.server.sqlparser.sqlobject.statement.query.order_by.OrderBy;
import drds.server.sqlparser.visitor.Visitor;

/**
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class UnionQuery extends AbstractSqlObject implements IQuery {

	private IQuery left;
	private IQuery right;
	private UnionOperator unionOperator = UnionOperator.UNION;
	private OrderBy orderBy;

	public void setUnionOperator(UnionOperator unionOperator) {
		this.unionOperator = unionOperator;
	}

	public UnionOperator getUnionOperator() {
		return unionOperator;
	}

	public UnionQuery() {

	}

	public void setLeft(IQuery left) {
		if (left != null) {
			left.setParent(this);
		}
		this.left = left;
	}

	public IQuery getLeft() {
		return left;
	}

	public void setRight(IQuery right) {
		if (right != null) {
			right.setParent(this);
		}
		this.right = right;
	}

	public IQuery getRight() {
		return right;
	}

	public void setOrderBy(OrderBy orderBy) {
		if (orderBy != null) {
			orderBy.setParent(this);
		}
		this.orderBy = orderBy;
	}

	public OrderBy getOrderBy() {
		return orderBy;
	}

	@Override
	protected void accept0(Visitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, left);
			acceptChild(visitor, right);
			acceptChild(visitor, orderBy);
		}
		visitor.endVisit(this);
	}

}
